namespace TXLooker.WorkItemExtention.WIQL
{
    using System;

    public class NodeArithmetic : NodeList
    {
        private Arithmetic m_operator;

        public NodeArithmetic() : base(NodeType.Arithmetic, 2)
        {
        }

        public override void Bind(IExternal e, NodeTableName tableContext, NodeFieldName fieldContext)
        {
            this.Left.Bind(e, tableContext, fieldContext);
            this.Right.Bind(e, tableContext, fieldContext);
            Tools.EnsureSyntax(this.Left.IsConst, SyntaxError.ExpectingConst, this.Left);
            Tools.EnsureSyntax(this.Right.IsConst, SyntaxError.ExpectingConst, this.Right);
            base.Bind(e, tableContext, fieldContext);
        }

        public override Node Optimize(IExternal e, NodeTableName tableContext, NodeFieldName fieldContext)
        {
            base.OptimizeChildren(e, tableContext, fieldContext);
            return base.Optimize(e, tableContext, fieldContext);
        }

        public override string ToString()
        {
            return base.JoinChildren(" " + ArithmeticalOperators.GetString(this.m_operator) + " ");
        }

        public Arithmetic Arithmetic
        {
            get
            {
                return this.m_operator;
            }
            set
            {
                this.m_operator = value;
            }
        }

        public override DataType DataType
        {
            get
            {
                return this.Left.DataType;
            }
        }

        public Node Left
        {
            get
            {
                return this[0];
            }
            set
            {
                this[0] = value;
            }
        }

        public override Priority Priority
        {
            get
            {
                return Priority.AddOperator;
            }
        }

        public Node Right
        {
            get
            {
                return this[1];
            }
            set
            {
                this[1] = value;
            }
        }
    }
}

